<?php
//魔法转义数据
function magicstr($str) {
    if(!$str) return '';
    $patterns_html=array(
        '/on(load|click|dbclick|mouseover|mousedown|mouseup)="[^"]+"/i',
        '/<script[^>]*?>([\w\W]*?)<\/script>/i'
    );
    $replace=array('','');
    $str=preg_replace($patterns_html,$replace,rtrim(ltrim($str)));

    if(!get_magic_quotes_gpc()) $str=addslashes($str);
    return $str;
}
//页面跳转
function redirect($content,$action,$url=''){
    $script= "<script type='text/javascript'>";
    if($content) $script.= "alert('$content');";
    switch ($action){
        case "back":$script.="$url;window.history.back();";break;
        case "close":$script.="$url;window.opener=null;window.close();";break;
        case "redirect":$script.= "window.location.href='$url';\n";break;
    }
    die($script."</script>");exit();
}

function telcheck($tel){
    return preg_match('/^((1)?(778|604|250|226|416|613|902|204)|(1888|1800|1855|1866))[0-9]{7}$/',str_replace('-','',str_replace(' ','',$tel)));
}

?>
